import axios from 'axios';

// 登录请求方法
const loginRequest = (url, params) => {
  return axios.post(url, params)
    .then(res => res.data)
    .catch(function (error) {
      console.log(error);
    });
};
// 通用Key-value公用方法
const req = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
      'Authorization': localStorage.getItem('Authorization')
    },
    params: params
  }).then(res => res.data);
};

// 通用JSON公用方法
const commonJsonRequest = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      Authorization: localStorage.getItem('Authorization')
    },
    data: params
  }).then(res => res.data);
};

//通用Url带参数请求方式
const commonUrlRequest = (method, url) => {
  return axios({
    method: method,
    url: url,
    headers: {
      Authorization: localStorage.getItem('Authorization')
    }
  }).then(res => res.data);
};

export {
  loginRequest,
  req,
  commonJsonRequest,
  commonUrlRequest
}
